package com.ssm.xml.controller;

import com.alibaba.fastjson.JSON;
import com.ssm.xml.entity.Directory;
import com.ssm.xml.service.DirectoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/dir")
public class DirectoryController {
    @Autowired
    private DirectoryService directoryService;

    @RequestMapping("/getAllDir")
    public String getAllDir(){
        return JSON.toJSONString(directoryService.getAllDir());
    }

    @RequestMapping("/deleteDir")
    public String deleteDir(int id){
        directoryService.deleteDir(id);
        return "redirect:index";
    }

    @RequestMapping("/addDir")
    public String addDir(Directory directory){
        directoryService.addDir(directory);
        return "redirect:index";
    }

    @RequestMapping("/rename")
    public String rename(Directory directory){
        directoryService.rename(directory);
        return "redirect:index";
    }
}
